package cn.itcast.cxf.rs.server;

import cn.itcast.cxf.domain.Car;
import cn.itcast.cxf.domain.User;
import cn.itcast.cxf.service.IUserService;
import cn.itcast.cxf.service.UserServiceImpl;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;

/**
 * Created by Think on 2017/9/18.
 */
public class RS_Server {

    //CXF发布方式
    public static void main(String[] args) {
        //创建业务接口实现类对象
        IUserService userService = new UserServiceImpl();
        String address = "http://localhost:9999";
        // 服务器FactoryBean创建服务
        JAXRSServerFactoryBean jaxrsServerFactoryBean = new JAXRSServerFactoryBean();
        jaxrsServerFactoryBean.setResourceClasses(User.class, Car.class);
        jaxrsServerFactoryBean.setServiceBean(userService);
        jaxrsServerFactoryBean.setAddress(address);
        // 想看Soap协议（== http协议+xml数据）
//        jaxrsServerFactoryBean.getInInterceptors().add(new LoggingInInterceptor());//输入拦截器日志
//        jaxrsServerFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor());//输出拦截器日志
        jaxrsServerFactoryBean.create();
        System.out.println("CXF方式发布服务成功");
    }
}
